From 3420b7e654afc11e0f93f6c8d726785ea2cd8ab5 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 23 Aug 2006 08:17:09 +0000 Subject: [PATCH] Fix logic at the end of strings. 2006-08-23 Tor Lillqvist * gtk/gtkfilesystemwin32.c (_gtk_file_system_win32_path_compare): Fix logic at the end of strings. * gtk/gtkfilesystemwin32.c: Maintain a hash table of live handles and check that we have no outstanding handles at finalization time. (Copying what Matthias did for gtkfilesystemunix.c) --- ChangeLog | 12 ++++- gtk/gtkfilesystemwin32.c | 97 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c1eb9f7a2..0d72985edf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-08-23 Tor Lillqvist + + * gtk/gtkfilesystemwin32.c (_gtk_file_system_win32_path_compare): + Fix logic at the end of strings. + + * gtk/gtkfilesystemwin32.c: Maintain a hash table of live + handles and check that we have no outstanding handles at + finalization time. (Copying what Matthias did for + gtkfilesystemunix.c) + 2006-08-23 Matthias Clasen * gtk/gtkfilesystemunix.c: Maintain a hash table @@ -5,7 +15,7 @@ handles at finalization time. (Copying what Federico did for gtkfilesystemgnomevfs.c) -2006-08-22 Matthias Clasen +2007-08-22 Matthias Clasen * Branch for 2.10 diff --git a/gtk/gtkfilesystemwin32.c b/gtk/gtkfilesystemwin32.c index 05166909cf..8582a2cb99 100644 --- a/gtk/gtkfilesystemwin32.c +++ b/gtk/gtkfilesystemwin32.c @@ -19,6 +19,11 @@ * Boston, MA 02111-1307, USA. */ +/* #define this if you want the program to crash when a file system gets + * finalized while async handles are still outstanding. + */ +#undef HANDLE_ME_HARDER + #include #include "gtkfilesystem.h" @@ -66,6 +71,8 @@ struct _GtkFileSystemWin32 guint32 drives; /* bitmask as returned by GetLogicalDrives() */ GHashTable *folder_hash; guint timeout; + + GHashTable *handles; }; /* Icon type, supplemented by MIME type @@ -356,6 +363,77 @@ gtk_file_system_win32_init (GtkFileSystemWin32 *system_win32) * be enough. */ system_win32->timeout = g_timeout_add_full (0, 1000, check_volumes, system_win32, NULL); + + system_win32->handles = g_hash_table_new (g_direct_hash, g_direct_equal); +} + +static void +check_handle_fn (gpointer key, gpointer value, gpointer data) +{ + GtkFileSystemHandle *handle; + int *num_live_handles; + + handle = key; + num_live_handles = data; + + (*num_live_handles)++; + + g_warning ("file_system_win32=%p still has handle=%p at finalization which is %s!", + handle->file_system, + handle, + handle->cancelled ? "CANCELLED" : "NOT CANCELLED"); +} + +static void +check_handles_at_finalization (GtkFileSystemWin32 *system_win32) +{ + int num_live_handles; + + num_live_handles = 0; + + g_hash_table_foreach (system_win32->handles, check_handle_fn, &num_live_handles); +#ifdef HANDLE_ME_HARDER + g_assert (num_live_handles == 0); +#endif + + g_hash_table_destroy (system_win32->handles); +} + +#define GTK_TYPE_FILE_SYSTEM_HANDLE_WIN32 (_gtk_file_system_handle_win32_get_type ()) + +typedef struct _GtkFileSystemHandle GtkFileSystemHandleWin32; +typedef struct _GtkFileSystemHandleClass GtkFileSystemHandleWin32Class; + +G_DEFINE_TYPE (GtkFileSystemHandleWin32, _gtk_file_system_handle_win32, GTK_TYPE_FILE_SYSTEM_HANDLE) + +static void +_gtk_file_system_handle_win32_init (GtkFileSystemHandleWin32 *handle) +{ +} + +static void +_gtk_file_system_handle_win32_finalize (GObject *object) +{ + GtkFileSystemHandleWin32 *handle; + GtkFileSystemWin32 *system_win32; + + handle = (GtkFileSystemHandleWin32 *)object; + + system_win32 = GTK_FILE_SYSTEM_WIN32 (GTK_FILE_SYSTEM_HANDLE (handle)->file_system); + + g_assert (g_hash_table_lookup (system_win32->handles, handle) != NULL); + g_hash_table_remove (system_win32->handles, handle); + + if (G_OBJECT_CLASS (_gtk_file_system_handle_win32_parent_class)->finalize) + G_OBJECT_CLASS (_gtk_file_system_handle_win32_parent_class)->finalize (object); +} + +static void +_gtk_file_system_handle_win32_class_init (GtkFileSystemHandleWin32Class *class) +{ + GObjectClass *gobject_class = (GObjectClass *) class; + + gobject_class->finalize = _gtk_file_system_handle_win32_finalize; } static void @@ -367,6 +445,8 @@ gtk_file_system_win32_finalize (GObject *object) g_source_remove (system_win32->timeout); + check_handles_at_finalization (system_win32); + /* FIXME: assert that the hash is empty? */ g_hash_table_destroy (system_win32->folder_hash); @@ -779,11 +859,17 @@ queue_callback (enum callback_types type, gpointer data) static GtkFileSystemHandle * create_handle (GtkFileSystem *file_system) { + GtkFileSystemWin32 *system_win32; GtkFileSystemHandle *handle; - handle = g_object_new (GTK_TYPE_FILE_SYSTEM_HANDLE, NULL); + system_win32 = GTK_FILE_SYSTEM_WIN32 (file_system); + + handle = g_object_new (GTK_TYPE_FILE_SYSTEM_HANDLE_WIN32, NULL); handle->file_system = file_system; + g_assert (g_hash_table_lookup (system_win32->handles, handle) == NULL); + g_hash_table_insert (system_win32->handles, handle, handle); + return handle; } @@ -2736,7 +2822,14 @@ _gtk_file_system_win32_path_compare (const gchar *path1, else break; } - return *path1 - *path2; + if (!*path1 && !*path2) + return 0; + else if (!*path1) + return -1; + else if (!*path2) + return 1; + else + return g_unichar_toupper (g_utf8_get_char (path1)) - g_unichar_toupper (g_utf8_get_char (path2)); } #define __GTK_FILE_SYSTEM_WIN32_C__ -- 2.30.2